import { IPSApplication } from './ipsapplication';
import { IPSApplicationLogic } from './ipsapplication-logic';
import { IPSAppDataEntity } from './dataentity/ipsapp-data-entity';
import { IPSAppUILogic } from './logic/ipsapp-uilogic';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSApplicationLogicImpl extends PSModelObjectImpl implements IPSApplicationLogic {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get eventArg(): string {
    return this.M.eventArg;
  }

  get eventArg2(): string {
    return this.M.eventArg2;
  }

  get eventNames(): string {
    return this.M.eventNames;
  }

  get logicTag(): string {
    return this.M.logicTag;
  }

  get logicType(): string {
    return this.M.logicType;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected psappdataentity: IPSAppDataEntity | null = null;

  getPSAppDataEntity(): IPSAppDataEntity | null {
    if (this.psappdataentity != null) return this.psappdataentity;
    const value = this.M.getPSAppDataEntity;
    if (value == null) {
      return null;
    }
    this.psappdataentity = this.getPSModel4('app.dataentity.IPSAppDataEntity', value, 'getPSAppDataEntity') as IPSAppDataEntity;
    return this.psappdataentity;
  }

  get psAppDataEntity(): IPSAppDataEntity | null {
    return this.getPSAppDataEntity();
  }

  getPSAppDataEntityMust(): IPSAppDataEntity {
    const value = this.getPSAppDataEntity();
    if (value == null) {
      throw new Error('未指定触发逻辑所在应用实体');
    }
    return value;
  }

  protected psappuilogic: IPSAppUILogic | null = null;

  getPSAppUILogic(): IPSAppUILogic | null {
    if (this.psappuilogic != null) return this.psappuilogic;
    const value = this.M.getPSAppUILogic;
    if (value == null) {
      return null;
    }
    const ipsapplication = this.getParentPSModelObject('app.IPSApplication') as IPSApplication;
    if (ipsapplication != null) {
      this.psappuilogic = ipsapplication.findPSAppUILogic(value);
    }
    return this.psappuilogic;
  }

  get psAppUILogic(): IPSAppUILogic | null {
    return this.getPSAppUILogic();
  }

  getPSAppUILogicMust(): IPSAppUILogic {
    const value = this.getPSAppUILogic();
    if (value == null) {
      throw new Error('未指定触发应用预置界面逻辑');
    }
    return value;
  }

  get scriptCode(): string {
    return this.M.scriptCode;
  }

  get timer(): number {
    return this.M.timer != null ? this.M.timer : 0;
  }

  get triggerType(): 'TIMER' | 'CTRLEVENT' | 'VIEWEVENT' | 'APPEVENT' | 'ITEMVISIBLE' | 'ITEMENABLE' | 'ITEMBLANK' | 'ITEMDYNACLASS' | 'RENDER' | 'ATTRIBUTE' | 'CUSTOM' | 'VUE_DIRECTIVE' {
    return this.M.triggerType || 'APPEVENT';
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSApplicationLogicImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.IPSApplicationLogic') return true;
    return super.instanceof(cls);
  }
}
